#include <iostream>
#include <map>
using namespace std;
map<string, long long>mp;
int main()
{
    string s;
    long long x;
    int c;
    for (int i = 0; i < 6; i++) {
        cin >> s;
        cin >> x;
        mp[s] += x;
        cin >> c;
        while (c--) {
            cin >> s;
            cin >> x;
            mp[s] += x;
        }
    }
    cout << "atk " << mp["atk"] << endl;
    cout << "atkper " << mp["atkper"] << endl;
    cout << "def " << mp["def"] << endl;
    cout << "spd " << mp["spd"] << endl;
    return 0;
}